package com.lzq.leetcode.lanqiao.th12;

import java.util.Scanner;

public class s6 {

    private static final int MAX = 1414215;

    static long[] a = new long[MAX+1];
    static long[] s = new long[MAX+1];

    public static long getSum(int p) {
        // 二分查找，找到大区间
        int l = 1, r = MAX;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (a[mid] <= p) l = mid + 1;
            else r = mid - 1;
        }
        return s[r] + a[(int)(p - a[r])];
    }

    public static void main(String[] args) {

        a[1] = 1;
        s[1] = 1;
        for (int i=2; i<=MAX; i++) {
            a[i] = a[i-1] + i;
            s[i] = s[i-1] + a[i];
        }
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for (int i=0; i<t; i++) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            System.out.println(getSum(r) - getSum(l-1));
        }

    }
}
